﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KamLib;

namespace Ext.Net
{
    public static class ExtDebugUtils
    {
        public static Tuple<string, object>[] AsDebug(this ConfigOptionsCollection list, bool fullOnly = true)
        {
            var cc = new ClientConfig(); 
            var list2 = fullOnly
                ? list.Where(a =>
                {
                    var v = a.Value.Value;
                    if (v == null || (v is string && (string)v != string.Empty)) 
                        return false;
                    var originalValue = a.Value.Value;
                    var defaultValue = a.Value.DefaultValue;

                    return !cc.IsNullEmptyOrDefault(ref defaultValue, ref originalValue, a.Value);
                })
                : list;

            return list2
                .Select(a => new Tuple<string, object>(a.Key, a.Value.Value))
                .OrderBy(a => a.Item1).ToArray();
        }
    }
}
